﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WHC.Hotel.Entity;
using WHC.Hotel.BLL;
using WHC.OrderWater.Commons;


namespace WHC.Hotel.UI
{
    public partial class FrmEditSuiteMulti : BaseForm
    {
        public FrmEditSuiteMulti()
        {
            InitializeComponent();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void InitRoomType()
        {
            List<TeaSuiteTypeInfo> list = BLLFactory<TeaSuiteType>.Instance.GetAll();
            this.cmbRoomType.Items.Clear();
            foreach (TeaSuiteTypeInfo typeInfo in list)
            {
                CListItem item = new CListItem(typeInfo.Name, typeInfo.Name);
                this.cmbRoomType.Items.Add(item);
            }
        }

        private void FrmEditRoomType_Load(object sender, EventArgs e)
        {
            InitRoomType();
            this.txtStart.Focus();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            #region 输入验证
            if (this.cmbRoomType.Text.Trim().Length == 0)
            {
                MessageUtil.ShowTips("请输入房间类型");
                this.cmbRoomType.Focus();
                return;
            }
            if (this.txtStart.Text.Trim().Length == 0 || this.txtEnd.Text.Trim().Length == 0)
            {
                MessageUtil.ShowTips("请输入房间范围的起止编号");
                this.txtStart.Focus();
                return;
            }
            if (this.txtStart.Value > this.txtEnd.Value)
            {
                MessageUtil.ShowTips("房间范围的起始编号不能小于结束编号");
                this.txtStart.Focus();
                return;
            } 
            #endregion                       

            try
            {
                int start = Convert.ToInt32(this.txtStart.Text);
                int end = Convert.ToInt32(this.txtEnd.Text);
                string suffix = this.txtSuffix.Text;

                TeaSuiteInfo info = null;
                for (int i = start; i <= end; i++)
                {
                    info = new TeaSuiteInfo();

                    #region 构造对象信息
                    string roomNo = i.ToString();
                    if (this.radBefore.Checked)
                    {
                        roomNo = this.txtSuffix.Text + roomNo;
                    }
                    else if (this.radAfter.Checked)
                    {
                        roomNo = roomNo + this.txtSuffix.Text;
                    }
                    info.RoomNo = roomNo;

                    info.Region = this.txtArea.Text;
                    info.Status = TeaSuiteStatus.可供;
                    info.RoomType = this.cmbRoomType.Text;
                    info.Waiter = this.txtWaiter.Text;
                    info.Note = this.txtNote.Text;
                    #endregion

                    try
                    {
                        BLLFactory<TeaSuite>.Instance.Insert(info);
                    }
                    catch (Exception ex)
                    {
                        LogHelper.Error(ex);//记录错误，继续执行
                    }
                }

                MessageUtil.ShowTips("保存成功");
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
                MessageUtil.ShowError(ex.Message);
            }
        }
    }
}
